package me.sapling.view;

import me.sapling.model.PageContent;

/**
 * @author sapling
 */
public class LRUPanel extends AbstractPanel {

    public LRUPanel(PageContent[] pages, PageContent[] contents) {
		super(pages, contents);
	}

	@Override
	protected void routerInit() {
		for (int i = 0; i < contentRouter.length; i++) {
			if (i == 0) {
				contentRouter[0][0] = contents[0];
				reserve[0] = true;
				reserveCount++;
			} else {
				contentRouter[i] = contentRouter[i - 1].clone();
				PageContent temp = null;
				int j;
				for (j = 0; j < pageNumInMemory; j++) {
					if (contentRouter[i][j] == contents[i]) {
						temp = contents[i];
						break;
					}
				}
				if (temp != null) {
					System.arraycopy(contentRouter[i], 0, contentRouter[i], 1, j);
					reserve[i] = false;
					contentRouter[i][0] = temp;
					contentOut[i] = null;
				} else {
					reserve[i] = true;
					reserveCount++;
					contentOut[i] = contentRouter[i][pageNumInMemory - 1];
					System.arraycopy(contentRouter[i], 0, contentRouter[i], 1, pageNumInMemory - 1);
					contentRouter[i][0] = contents[i];
				}
			}
		}
	}

	@Override
	protected void arithmetic(int i) {

	}
}
